<?php

// +----------------------------------------------------------------------
// | Think.Admin
// +----------------------------------------------------------------------
// | 版权所有 2014~2017 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | github开源项目：https://github.com/zoujingli/Think.Admin
// +----------------------------------------------------------------------

namespace app\store\service;

use service\DataService;
use service\ToolsService;
use think\Db;

/**
 * 商城订单服务
 * Class OrderService
 * @package app\store
 */
class RechargeService
{


    /**
     * 订单主表数据处理
     * @param array $list
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function buildRechargeList(&$list)
    {
        $mids = array_unique(array_column($list, 'mid'));
        $memberList = Db::name("StoreMember")->field('id,mobile')->whereIn('id', $mids)->select();
        $mealList = Db::name('StoreMeal')->select();
        $novelMealList = Db::name('NovelMeal')->select();
        $comboList = Db::name('StoreCombos')->select();

        foreach ($list as $key => $vo) {
            $list[$key]['member']['nickname'] = '';
            foreach ($memberList as $member) {
                if($vo['mid'] === $member['id']) {
                    $list[$key]['member']['mobile'] = $member['mobile'];
                }
            }
            $list[$key]['meal'] = [];
            foreach($mealList as $meal) {
                ($vo['meal_id'] === $meal['id'] && $vo['subject'] == 1) && $list[$key]['meal'] = $meal;
            }
            foreach($comboList as $meal) {
                ($vo['meal_id'] === $meal['id'] && $vo['subject'] == 2) && $list[$key]['meal'] = $meal;
            }
            foreach($novelMealList as $meal) {
                ($vo['meal_id'] === $meal['id'] && $vo['subject'] == 3) && $list[$key]['meal'] = $meal;
            }
            foreach($comboList as $meal) {
                ($vo['meal_id'] === $meal['id'] && $vo['subject'] == 4) && $list[$key]['meal'] = $meal;
            }
        }
        return $list;
    }

}